﻿using System.Data;
using ET;
namespace DAL
{
    public class Order_Detail_DAL : clsConnect
    {
        private static readonly clsConnect cls = new clsConnect();
        #region[Get-Data]
        public DataTable GetOrderDetail(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", id);
            return cls.GetData("sp_tb_Order_Detail_Edit");
        }
        public DataTable GetOrderDetailOrder(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", id);
            return cls.GetData("sp_tb_Order_Detail_Order");
        }
        public DataTable GetOrderDetailOrderQuality(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Detail_Id", id);
            return cls.GetData("sp_tb_Order_Detail_Quality_Edit");
        }
        public DataTable GetOrderDetailReviewSum(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", id);
            return cls.GetData("sp_tb_Order_Detail_Edit_Sum");
        }
        public DataTable GetOrderDetailTemp(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Users_Id", id);
            return cls.GetData("sp_tb_Order_Detail");
        }
        public DataTable GetOrderDetailTempEdit(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Detail_Id", id);
            return cls.GetData("sp_tb_Order_Detail_Temp_Edit");
        }
        public DataTable GetOrderDetailTempTotal()
        {
            cls.CreateNewSqlCommand();
            return cls.GetData("sp_tb_Order_Detail_Total");
        }
        #endregion

        #region[Insert-Update-Delete]
        public bool InsertOrderDetail(Order_Detail_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", data.Order_Id);
            cls.AddParameter("@Materials_Id", data.Materials_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);

            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);

            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);

            cls.AddParameter("@Order_Detail_Total_Price", data.Order_Detail_Total_Price);
            cls.AddParameter("@Order_Detail_Note", data.Order_Detail_Note);
            cls.AddParameter("@IsActive", data.IsActive);
            return cls.ExecuteNonQuery("sp_tb_Order_Detail_Insert");
        }
        public bool InsertOrderDetailTemp(OrderDetailTemp_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Materials_Id", data.Materials_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);

            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);

            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);

            cls.AddParameter("@Order_Detail_Total_Price", data.Order_Detail_Total_Price);
            cls.AddParameter("@Order_Detail_Note", data.Order_Detail_Note);
            cls.AddParameter("@Users_Id", data.Users_Id);
            return cls.ExecuteNonQuery("sp_tb_Order_Detail_Temp_Insert");
        }
        public bool UpdateOrderDetailTemp(OrderDetailTemp_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Detail_Id", data.Order_Detail_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);
            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);
            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);
            cls.AddParameter("@Order_Detail_Note", data.Order_Detail_Note);
            return cls.ExecuteNonQuery("sp_tb_Order_Detail_Temp_Update");
        }
        public bool UpdateOrderDetail(Order_Detail_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Detail_Id", data.Order_Detail_Id);
            cls.AddParameter("@Order_Detail_Quality", data.Order_Detail_Quality);
            cls.AddParameter("@Order_Detail_Price", data.Order_Detail_Price);
            cls.AddParameter("@Order_Detail_CK_Percent", data.Order_Detail_CK_Percent);
            cls.AddParameter("@Order_Detail_CK", data.Order_Detail_CK);
            cls.AddParameter("@Order_Detail_VAT_Percent", data.Order_Detail_VAT_Percent);
            cls.AddParameter("@Order_Detail_VAT", data.Order_Detail_VAT);
            return cls.ExecuteNonQuery("sp_tb_Order_Detail_Update");
        }
        public bool UpdateOrderDetailStt(Order_Detail_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", data.Order_Id);
            cls.AddParameter("@IsActive", data.IsActive);
            return cls.ExecuteNonQuery("sp_tb_Order_Detail_Stt");
        }
        public bool DeleteOrderDetailTemp(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Detail_Id", id);
            cls.ExecuteNonQuery("sp_tb_Order_Detail_Temp_Delete");
            return true;
        }
        public bool DeleteOrderDetailTempAll()
        {
            cls.CreateNewSqlCommand();
            return cls.ExecuteNonQuery("sp_tb_Order_Detail_Temp_Delete_All");
        }
        public bool DeleteOrderDetailTempAllByUser(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Users_Id", id);
            return cls.ExecuteNonQuery("sp_tb_Order_Detail_Temp_Delete_Buy_User");
        }
        #endregion

        #region[Review]
        public bool Review(Order_Detail_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", data.Order_Id);
            cls.AddParameter("@IsActive", data.IsActive);
            cls.AddParameter("@Users_Id_Review", data.Users_Id_Review);
            return cls.ExecuteNonQuery("sp_tb_Order_Detail_Review");
        }
        #endregion

        #region[Sum-Order]
        public DataTable GetOrderDetailSum(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Order_Id", id);
            return cls.GetData("sp_tb_Order_Detail_Sum");
        }
        #endregion
    }
}